import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  HttpStatus,
} from '@nestjs/common';
import { TagService } from './tag.service';
import {
  CreateTagReqDto,
  CreateTagResFailDto,
  CreateTagResSuccessDto,
} from './dto/create-tag.dto';
import { UpdateTagDto } from './dto/update-tag.dto';
import { ApiResponse, ApiTags } from '@nestjs/swagger';
import { GetTagResSuccessDto, GetTagResFailDto } from './dto/get-tag.dto';
import {
  GetAllTagResFailDto,
  GetAllTagResSuccessDto,
} from './dto/getAll-tag.dto';

@Controller('tag')
@ApiTags('tag')
export class TagController {
  constructor(private readonly tagService: TagService) {}

  @ApiResponse({
    status: HttpStatus.CREATED,
    type: CreateTagResSuccessDto,
    description: '创建标签成功',
  })
  @ApiResponse({
    status: HttpStatus.ACCEPTED,
    type: CreateTagResFailDto,
    description: '创建标签失败',
  })
  @Post('item')
  async create(@Body() createTagDto: CreateTagReqDto) {
    await this.tagService.create(createTagDto.tagname);
    return {
      success: true,
    };
  }

  @ApiResponse({
    status: HttpStatus.OK,
    type: GetTagResSuccessDto,
    description: '获取标签成功',
  })
  @ApiResponse({
    status: HttpStatus.ACCEPTED,
    type: GetTagResFailDto,
    description: '获取标签失败',
  })
  @Get('item')
  async findOne(@Query('tagname') tagname: string) {
    const tag = await this.tagService.findOne(tagname);
    if (tag) {
      return {
        success: true,
        data: tag,
      };
    } else {
      return {
        success: false,
        message: '没有找到该标签',
      };
    }
  }

  @ApiResponse({
    status: HttpStatus.OK,
    type: GetAllTagResSuccessDto,
    description: '获取标签成功',
  })
  @ApiResponse({
    status: HttpStatus.ACCEPTED,
    type: GetAllTagResFailDto,
    description: '获取标签失败',
  })
  @Get('list')
  async findAll() {
    return await this.tagService.findAll();
  }
}
